package org.helsoft.mojo;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.helsoft.mojo.api.AbstractPDEMojo;
import org.helsoft.mojo.api.PluginDescriptor;

/**
 * The goal of this Mojo it's to synchronize the manifest
 * infos with the pom.xml at runtime. The version of the project
 * into the pom, will the one of the plugin in the Manifest.MF.
 * 
 * @author steg
 *
 * @goal init

 * @phase initialize
 * 
 */
public class InitMojo extends AbstractPDEMojo {

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		PluginDescriptor pd = getPluginDescriptor();
		String version = pd.getBundleVersion();
		MavenProject project = getProject();
		if (version != null && !version.trim().isEmpty()) {
			project.setVersion(version);
			project.getModel().setVersion(version);
			project.getOriginalModel().setVersion(version);
		}
	}

}
